home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / FDF101.ARJ / ELIB.ZOO / delete.c < prev    next >
C/C++ Source or Header  |  1992-04-30  |  495b  |  25 lines

  1. #include <sys/stat.h>
  2.  
  3.  
  4.  
  5. /*
  6.  * delete_file
  7.  *
  8.  * given the name of a file, attempt to delete it and return zero on success,
  9.  * non-zero if not.  'force' parameter, if non-zero, will try to change the
  10.  * mode of a file from read-only to delete it.
  11.  */
  12. int delete_file(char *file, char force)
  13.  
  14. {
  15.     if (force) {
  16.         struct stat statbuf;
  17.  
  18.         if ((!stat(file, &statbuf)) && (!(statbuf.st_mode & S_IWRITE)))
  19.             chmod(file, statbuf.st_mode | S_IWRITE);
  20.     }
  21.  
  22.     return unlink(file);
  23. }
  24.  
  25.